package com.ygqh.baby.controller.os;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.po.YgProductSecond;
import com.ygqh.baby.service.YgProductSecondService;
import com.ygqh.baby.service.impl.DocumentConstant;
@Controller
@RequestMapping("/os")
public class TestOs {
	@Value("${countdown.startTime}")
	private String startTime;
	@Value("${countdown.endTime}")
	private String endTime;
	@Autowired
	private DocumentConstant documentConstant;
	@Autowired
	private YgProductSecondService ygProductSecondService;
	@RequestMapping("go")
	@ResponseBody
	public JSONPObject go(String callback) {
		YgProductSecond second=ygProductSecondService.findActive();
		Map<String,Object> map=new HashMap<String, Object>();
		if(second!=null){
		SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		
		 map.put("endTime",second.getEndTime());
		 map.put("startTime",second.getStartTime());
		 map.put("currTime",df.format(new Date()));
		 
		//比较当前时间是否大于startTime ,大于则开始，		
		 
	     map.put("isStart",second.getStartTime().after(new Date())?"0":"1");
		//比较当前时间是否大于endTime ,大于则结束，
	     map.put("isEnd",second.getEndTime().after(new Date())?"0":"1");
		}else{
			 map.put("isStart",0);
			 map.put("isEnd",1);
		}
		JSONPObject json = null;
		json = new JSONPObject(callback, Message.success(documentConstant.MESSAGE_SUCCESS, map));
		return json;
	}
}
